<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('ad_postback_config', function (Blueprint $table) {
            $table->engine  = 'InnoDB';
            $table->comment('媒体回传配置');

            $table->increments('id');
            $table->integer('create_time')->comment('创建时间')->unsigned()->default(0);
            $table->string('name', 64)->comment('名称')->default('');

            // roi控制
            $table->double('roi_per', 16, 4)->comment('控制roi百分比 0不控制')->unsigned()->default(0);
            $table->integer('roi_type')->comment('控制粒度')->unsigned()->default(0);

            // roi达标后
            $table->integer('roiok_keep')->comment('roi达标后-是否继续回传')->unsigned()->default(0);
            $table->integer('roiok_delay')->comment('roi达标后-延迟多长时间判断')->unsigned()->default(0);
            $table->integer('roiok_money_type')->comment('roi达标后-后续回传金额类型 1默认 2固定')->unsigned()->default(0);
            $table->double('roiok_money', 16, 4)->comment('roi达标后-后续回传固定金额')->unsigned()->default(0);

            $table->integer('creater_id')->comment('创建者id')->unsigned()->default(0);
            $table->string('creater', 64)->comment('创建者名称')->default('');

            // 金额回传控制
            $table->mediumText('orders_config')->comment('金额回传配置')->nullable();
            $table->integer('orders_type')->comment('金额回传方式 1全部 2单首冲')->unsigned()->default(0);

            // 后续还可以添加控制激活和注册逻辑

            $table->index('create_time');
            $table->index('name');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('ad_postback_config');
    }
};
